/*
*创建赛区
CreateDivision.js*/
import React, { PropTypes, Component } from 'react';
import { autobind } from 'core-decorators';
import { Button, Form, Input,Row,Col,message  } from 'antd';
import { connect } from 'react-redux';
import DepartmentList from './DepartmentList';

const FormItem = Form.Item;

/*
*divisionName [赛区名称]
*departmentData[所有报名]
*departmentIdList[部门id]
***/
const CreateDivision = ({
		dispatch,
		privateGame,
		id
	})=>{
    const {
    	divisionName,
    	departmentData,
    	departmentIdList,
    } = privateGame;
    console.log('CreateDivision>>',privateGame,id)
    function handleInput(e){
    	dispatch({
    		type:'privateGame/setState',
    		payload:{
    			'divisionName':e.target.value
    		}
    	})
    }
		function handleSubmit(e) {
			e.preventDefault();
			if(divisionName==''&&_.isEmpty(departmentIdList)){
				message.warning('请输入赛区名称');
				message.warning('请选择部门');
			}else if(divisionName==''&&!_.isEmpty(departmentIdList)){
				message.warning('请输入赛区名称');
			}else if(divisionName!==''&&_.isEmpty(departmentIdList)){
				message.warning('请选择部门');
			}else if(divisionName!==''&& !_.isEmpty(departmentIdList)){
				dispatch({
					type:'privateGame/createDivision',
					payload:{
						name:divisionName,
						departmentIdList:departmentIdList,
						competitionId:id
					}
				})
			}
			
			
		}
		
		return (
			<div>
			  <Form onSubmit={handleSubmit} layout="vertical">
          <FormItem
						label="请设置新赛区名称:"
				  >
	          <Input value={divisionName} onChange={handleInput}/>
		      </FormItem>
		      <FormItem
						label="部门:"
				  >
				  {
				  	departmentData?<DepartmentList
	         		departmentData={departmentData}
	         	/>:null
				  }
	         	
		      </FormItem>
          <FormItem>
						<Row type="flex" justify="end">
							<Col span={3} >
								<Button type="primary" htmlType="submit">确定</Button>
							</Col>
							<Col span={3}>
								<Button>取消</Button>
							</Col>
						</Row>
			    </FormItem>
			  </Form>
			</div>
		)
}

CreateDivision.propTypes = {
	// form: PropTypes.object.isRequired,
}

export default connect(({privateGame})=>({privateGame}))(CreateDivision)